package hibernate.patterns;

import java.lang.reflect.ParameterizedType;

@SuppressWarnings("unchecked")
public class ClassUtils {


    public static Class getGenericTypeArgument(Class clazz) {
        Class currentClass = clazz;
        while (!(currentClass.getGenericSuperclass() instanceof ParameterizedType)) {
            currentClass = currentClass.getSuperclass();
        }
        ParameterizedType firstParameterizedType = (ParameterizedType) currentClass.getGenericSuperclass();
        return (Class) firstParameterizedType.getActualTypeArguments()[0];
    }
}
